package com.itheima.chinamobileai.config;

import com.itheima.chinamobileai.constants.SystemConstants;
import com.itheima.chinamobileai.tool.PackageQueryTool;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiEmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
public class ChinaMobileConfig {
    
    @Bean
    @Primary
    public VectorStore vectorStore(OpenAiEmbeddingModel embeddingModel) {
        // 使用builder方式创建SimpleVectorStore
        return SimpleVectorStore.builder(embeddingModel).build();
    }
    
    @Bean
    public ChatClient chinaMobileChatClient(OpenAiChatModel chatModel,
                                            ChatMemory chatMemory,
                                            PackageQueryTool packageTool) {
        return ChatClient.builder(chatModel)
                .defaultSystem(SystemConstants.CHINA_MOBILE_SYSTEM)
                .defaultAdvisors(new SimpleLoggerAdvisor())
                .defaultAdvisors(MessageChatMemoryAdvisor.builder(chatMemory).build())
                .defaultTools(packageTool)
                .build();
    }
}